package com.aaa.service.impl;

import com.aaa.entity.PrivateMessage;
import com.aaa.mapper.PrivateMessageMapper;
import com.aaa.service.IPrivateMessageService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author Bean
 * @since 2021-09-05
 */
@Service
public class PrivateMessageServiceImpl extends ServiceImpl<PrivateMessageMapper, PrivateMessage> implements IPrivateMessageService {

    @Autowired
    PrivateMessageMapper privateMessageMapper;
    @Autowired
    NettyPushServerImpl nettyPushServer;

    public boolean add(String uname,PrivateMessage privateMessage){
        if ( privateMessageMapper.add(privateMessage)==1){
            nettyPushServer.pushidServer(privateMessage.getReceiveId().toString(),uname+"给小主发送信息啦~");
            return true;
        }else{
            return false;
        }
    }

    public List<Map<String,Object>> seleinform(Integer uid){
        return privateMessageMapper.seleinform(uid);
    }

    public List<Map<String,Object>> seleone(Integer uid,Integer id){
        List<Map<String, Object>> seleone = privateMessageMapper.seleone(uid, id);
        for (Map<String, Object> map : seleone) {
            Integer state = (Integer) map.get("state");
            if (state==0){
                Integer idd = (Integer) map.get("id");
                privateMessageMapper.updastate(idd,1);
            }
        }
        return seleone;
    }
}
